#include "Player_impl.h"
#include <mmsystem.h>
#pragma comment(lib, "vfw32.lib")

Player_impl::Player_impl()
{
    state_.currentState = PlayerState::stop;
    state_.startPos = state_.endPos = state_.length = state_.curentPos = 0;
}

Player_impl::~Player_impl()
{
}
void Player_impl::Init(HWND hwnd, HINSTANCE hInst)
{
    playerWnd_ = MCIWndCreate(hwnd, hInst, 
        MCIWNDF_NOTIFYPOS|MCIWNDF_NOMENU|MCIWNDF_NOERRORDLG|MCIWNDF_NOTIFYMODE|MCIWNDF_SHOWALL,
        NULL);
    ShowWindow(playerWnd_, SW_HIDE);
}
bool Player_impl::Play(TCHAR* fileName)
{
    MCIWndOpen(playerWnd_, fileName, NULL);
	MCIWndPlay(playerWnd_);
    state_.length = MCIWndGetLength(playerWnd_);
    state_.currentState = PlayerState::play;
    return true;

}
bool Player_impl::Repeate()
{
    MCIWndPlayFromTo(playerWnd_, state_.startPos, state_.endPos);
    return true;
}
PlayerState Player_impl::GetState()
{
    state_.curentPos = MCIWndGetPosition(playerWnd_);
    return state_;
}
void Player_impl::SetState(PlayerState ps)
{
    state_ = ps;
}
bool Player_impl::PlayFrom(long pos)
{
    MCIWndPlayFrom(playerWnd_, pos);
    return true;

}
bool Player_impl::Pause()
{
    return true;
}
bool Player_impl::Stop()
{
    return true;
}